using System;
using UnityEngine;
using Random = UnityEngine.Random;

namespace Prototype.FeedTheWorld
{
    public class SpawnManager : MonoBehaviour
    {
        public GameObject[] animalPrefabs;
        private float spawnRangeX = 10;
        private float spawnPosZ = 32;
        private float startDelay = 2;
        private float spawnInterval = 1.5f;

        private void Start()
        {
            InvokeRepeating("SpawnRandomAnimal",startDelay,spawnInterval);
        }

        void SpawnRandomAnimal()
        {
            var randomAnimalPrefab = animalPrefabs[Random.Range(0, animalPrefabs.Length)];
            var randomPosition = new Vector3(Random.Range(-spawnRangeX, spawnRangeX), 0, spawnPosZ);
            Instantiate(randomAnimalPrefab, randomPosition, randomAnimalPrefab.transform.rotation);
        }
    }
}